package com.ruoyi.system.outto.thread;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.Constant;
import com.ruoyi.common.enums.SalerStatus;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.V2.inter.mapper.*;
import com.ruoyi.system.model.domain.*;
import com.ruoyi.system.model.mapper.*;
import com.ruoyi.system.V2.inter.service.IInterRecService;
import com.ruoyi.system.outto.core.LCConstant;
import com.ruoyi.system.outto.game.*;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;

/**
 * @author lz
 * @version 1.0
 * @date 2022/6/18 9:04
 */
@Component
public class OutThread {


    @Autowired
    private KMAPI kmapi;
    private List<AccountInfo> accountInfoList;
    @Autowired
    private LCAPI lcapi;
    @Autowired
    private IJIZAIAPI ijizaiapi;
    @Autowired
    private LDAPI ldapi;
    @Autowired
    private LDV2API ldv2API;
    @Autowired
    private SBOAPI sboapi;

    @Autowired
    private WUYOUAPI wuyouapi;
    @Autowired
    private KANGEHAOAPI kangehaoapi;
    @Autowired
    private KAKAAPI kakaapi;
    @Autowired
    private IMMAPI immapi;
    @Autowired
    private BQWAPI bqwapi;
    @Autowired
    private IPXXXAPI ipxxxapi;
    @Autowired
    private IPXAPI ipxapi;
    @Autowired
    private LSHENAPI lshenapi;
    @Autowired
    private YDDDV2Api ydddv2Api;
    @Autowired
    private IZJYAPI izjyapi;
    @Autowired
    private ITQYIAPI itqyiapi;
    @Autowired
    private IJYMAPI ijymapi;
    @Autowired
    private KEJINAPI kejinapi;
    @Autowired
    private IHHBAPI ihhbapi;
    @Autowired
    private IYXGAPI iyxgapi;
    @Autowired
    private ILJAPI iljapi;
    @Autowired
    private IKGAPI ikgapi;
    @Autowired
    private IYX915API iyx915api;
    @Autowired
    private JYYAPI jyyapi;
    @Autowired
    private IPANZHIAPI ipanzhiapi;
    @Autowired
    private YDDDApi ydddApi;
    @Autowired
    private ISDZAPI isdzapi;
    @Autowired
    private CRAPI crapi;
    @Autowired
    private ZHUANAPI zhuanapi;
    @Autowired
    private MENGQAPI mengqapi;

    private String operType = "1"; //1、编辑或删除  2、新增

    @Autowired
    private SSGAPI ssgapi;
    @Autowired
    private IYZJAPI iyzjapi;
    @Autowired
    private LXYAPI lxyapi;
    @Autowired
    private CYXAPI cyxapi;

    @Autowired
    private QSHANAPI qshanapi;

    @Autowired
    private MHWAPI mhwapi;
    @Autowired
    private SLAPI slapi;
    @Autowired
    private TXYAPI txyapi;

    @Autowired
    private IYX7881API iyx7881API;

    @Resource
    private OutRecMapper outRecMapper;

    @Resource
    private ArtRecMapper artRecMapper;
    @Resource
    private ApiTaskPoolMapper apiTaskPoolMapper;

    @Resource
    private ApiReqCopyMapper apiReqCopyMapper;

    @Resource
    private AccountInfoMapper accountInfoMapper;

    //    private ApiTaskPool apiTaskPool;
    @Resource
    private SalePartnerMapper salePartnerMapper;
    @Autowired
    private IInterRecService interRecService;

    private List<String> YDList;

//    private BigDecimal price = new BigDecimal(0);//原始价格

    private static Date lastDate = new Date();

    /**
     * 状态码
     */
    public static final String CODE_TAG = "code";

    /**
     * 返回内容
     */
    public static final String MSG_TAG = "msg";
    public static final String OUTDI = "outId";


    @Transactional
    public void start(AccountInfo accountInfo, String type, int delType, Long taskId, List<Long> saleNames) {

        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.put(CODE_TAG, 200);
        ajaxResult.put(MSG_TAG, "操作成功");
        ajaxResult.put(OUTDI, null);

        String des = accountInfo.getDes();
        if(StringUtils.isNotEmpty(des)) {
            des = des
                    .replace("+" , "")
                    .replace("（" , "")
                    .replace("(" , "")
                    .replace("）" , "")
                    .replace(")" , "")
                    .replace("|" , "")
                    .replace("~" , "");

            accountInfo.setDes(des);
        }

        Integer suit = accountInfo.getSuit();
        if (Objects.isNull(suit)){
            accountInfo.setSuit(0);
        }
        Integer guns = accountInfo.getGuns();
        if (Objects.isNull(guns)){
            accountInfo.setGuns(0);
        }

        Integer heroes = accountInfo.getHeroes();
        if (Objects.isNull(heroes)){
            accountInfo.setHeroes(0);
        }

        Integer skins = accountInfo.getSkins();
        if (Objects.isNull(skins)){
            accountInfo.setSkins(0);
        }

        if (CollectionUtils.isEmpty(YDList)) {
            YDList = Arrays.asList(LCConstant.saleNameYDDS);
        }
        if (type.equals(Constant.add)) {
            for (Long saleId : saleNames) {
                add(saleId, ajaxResult, accountInfo,taskId);
            }
        } else if (type.equals(Constant.edit)) {
            this.operType = "1";
//            AccountInfo info = accountInfoMapper.selectAccountInfoById(accountInfo.getId());
            if (true){
//                apiTaskPool(taskId);
                for (Long saleId : saleNames) {
                    Long userId = accountInfo.getCreateId();
                    SalePartner salePartner = salePartnerMapper.selectSalePartnerById(saleId);

//                    //霸气玩
//                    String bqwid = accountInfo.getBqwid();
//                    if (salePartner.getSaleName().contains("BQW") && StringUtils.isEmpty(bqwid)){
//                        continue;
//                    }
//                    //交易猫
//                    Long jymid = accountInfo.getJymid();
//                    if (salePartner.getSaleName().contains("JYM") && Objects.isNull(jymid)){
//                        continue;
//                    }
//                    //少伯
//                    String sboid = accountInfo.getSboid();
//                    if (salePartner.getSaleName().contains("SBO") && StringUtils.isEmpty(sboid)){
//                        continue;
//                    }
//                    //转转
//                    String zid = accountInfo.getZid();
//                    if (salePartner.getSaleName().contains("ZHUAN") && StringUtils.isEmpty(zid)){
//                        continue;
//                    }
//                    Long kjsId = accountInfo.getKjsid();
//                    if (salePartner.getSaleName().contains("KJS") && Objects.isNull(kjsId)){
//                        continue;
//                    }

                    if (accountInfo.getPrice().compareTo(new BigDecimal(300)) < 0){
                        accountInfo.setPrice(accountInfo.getPrice().add(new BigDecimal(50)));
                    }

                    if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameLCC)) {
                        try {
                            ajaxResult = lcapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameMMM)) {
                        try {
                            ajaxResult = immapi.addAndEditGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNamePXXX)) {

                        try {
                            ajaxResult = ipxxxapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameTQYY)) {

                        try {
                            ajaxResult = itqyiapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }

                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameZJY)) {
                        try {
                            ajaxResult = izjyapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameKJS)) {

                        boolean b = interRecService.checkInter(LCConstant.saleNameLCC, accountInfo.getId(), userId);
                        if (b) {
                            try {
                                if (Objects.nonNull(accountInfo.getKjsid())){
                                    ajaxResult = kejinapi.editGame(accountInfo, userId, salePartner);
                                }else {
                                    ajaxResult.put(CODE_TAG, 500);
                                    ajaxResult.put(MSG_TAG, "无此三放ID");
                                }
                            } catch (GlobalException s) {
                                ajaxResult.put(CODE_TAG, 500);
                                ajaxResult.put(MSG_TAG, s.getMessage());
                            }
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameHHB)) {
                        try {
                            ajaxResult = ihhbapi.addAndEditAndDelGame(accountInfo, "mod", userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameYXG)) {
                        //游戏阁接口
                        try {
                            ajaxResult = iyxgapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNamePZZ)) {
                        //盼之接口
//                        boolean b = interRecService.checkInter1(LCConstant.saleNameLCC, accountInfo.getId(), userId);
                        if (true) {
                            try {
                                if (Objects.equals(accountInfo.getSaleState(),SalerStatus.unsold.getCode())){
                                    ajaxResult = ipanzhiapi.editGame(accountInfo, userId, salePartner);
                                }else {
                                    ajaxResult.put(CODE_TAG, 500);
                                    ajaxResult.put(MSG_TAG, "账号状态不对");
                                }
                            } catch (GlobalException s) {
                                ajaxResult.put(CODE_TAG, 500);
                                ajaxResult.put(MSG_TAG, s.getMessage());
                            }
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameSDZ)) {
                        //闪电猪接口
                        try {
                            ajaxResult = isdzapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameCR)) {
                        //超人接口
                        try {
                            ajaxResult = crapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameYDD)) {
                        //虞都
                        try {
                            ajaxResult = ydddApi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameLXY)) {
                        //乐逍遥
                        try {
                            ajaxResult = lxyapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameCYX)) {
                        //畅游星
                        try {
                            ajaxResult = cyxapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameLJ)) {
                        //龙将
                        try {
                            ajaxResult = iljapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameJYY)) {
                        //交易游
                        try {
                            //(1,添加) (2,修改)(3,上下架)
                            ajaxResult = jyyapi.addAndEditAndDelGame(accountInfo, userId, 2, false, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameKG)) {
                        //凯哥
                        try {
                            ajaxResult = ikgapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameYX915)) {
                        //YX915
                        try {
                            ajaxResult = iyx915api.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameYZJ)) {
                        //游之境
                        try {
                            ajaxResult = iyzjapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.getSaleNameKM)) {
                        //酷猫
                        try {
                            ajaxResult = kmapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameZHUAN)) {
                        //转转
                        try {
                            ajaxResult = zhuanapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameSBO)) {
                        //少伯
                        try {
                            ajaxResult = sboapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameJYM)) {
                        //交易猫
                        try {
                            ajaxResult = ijymapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameLDD)) {
                        //老达
                        try {
                            ajaxResult = ldapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameLDDV2)) {
                        //老达V2
                        try {
                            ajaxResult = ldv2API.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameQSHAN)) {
                        //青山
                        try {
                            ajaxResult = qshanapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameBQW)) {
                        //霸气玩
                        try {
                            ajaxResult = bqwapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameXINGL)) {
                        //破晓
                        try {
                            ajaxResult = ipxapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameLSHEN)) {
                        //雷神
                        try {
                            ajaxResult = lshenapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameYDDV2)) {
                        //虞都V2
                        try {
                            ajaxResult = ydddv2Api.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }

                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameMENGQ)) {
                        //萌奇
                        try {
                            ajaxResult = mengqapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameWYOU)) {
                        //无忧
                        try {
                            ajaxResult = wuyouapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameKGH)) {
                        //看个号
                        try {
                            if (StringUtils.isNotEmpty(accountInfo.getKangehaoid())){
                                ajaxResult = kangehaoapi.editGame(accountInfo, userId, salePartner);
                            }else {
                                ajaxResult.put(CODE_TAG, 500);
                                ajaxResult.put(MSG_TAG, "当前账号未推送,不可编辑");
                            }
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameKAKA)) {
                        //卡卡
                        try {
                            ajaxResult =kakaapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    }else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameMHW)) {
                        // 买号玩
                        try {
                            ajaxResult =mhwapi.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    }else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameSL)) {
                        // 三乐
                        try {
                            ajaxResult =slapi.addAndEditAndDelGame(accountInfo, "1", salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    }else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleName7881)) {
                        // 7881
                        try {
                            ajaxResult =iyx7881API.editGame(accountInfo, userId, salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    }else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameTXY)) {
                        //天下游
                        try {
                            ajaxResult = txyapi.editGame(accountInfo, userId,salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameMLY)) {
                        //米来游
                        try {
                            ajaxResult = izjyapi.editGame(accountInfo, userId,salePartner);
                        } catch (GlobalException s) {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, s.getMessage());
                        }
                    }
                    insertOutRec(ajaxResult, accountInfo, LCConstant.interEdit, salePartner,taskId);
                }
            }

        } else if (type.equals(Constant.del)) {
            this.operType = "1";
//            apiTaskPool(taskId);
            for (Long saleId : saleNames) {
                SalePartner salePartner = salePartnerMapper.selectSalePartnerById(saleId);

                //霸气玩
//                String bqwid = accountInfo.getBqwid();
//                if (salePartner.getSaleName().contains("BQW") && StringUtils.isEmpty(bqwid)){
//                    continue;
//                }
//                //交易猫
//                Long jymid = accountInfo.getJymid();
//                if (salePartner.getSaleName().contains("JYM") && Objects.isNull(jymid)){
//                    continue;
//                }
//                //少伯
//                String sboid = accountInfo.getSboid();
//                if (salePartner.getSaleName().contains("SBO") && StringUtils.isEmpty(sboid)){
//                    continue;
//                }
//                //转转
//                String zid = accountInfo.getZid();
//                if (salePartner.getSaleName().contains("ZHUAN") && StringUtils.isEmpty(zid)){
//                    continue;
//                }

                Long userId = accountInfo.getCreateId();
                Long id = accountInfo.getId();
                if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameLCC)) {
                    try {
                        ajaxResult = lcapi.delGame(id, userId, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameMMM)) {
                    try {
                        ajaxResult = immapi.delGame(id, 2, userId, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }

                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNamePXXX)) {

                    try {
                        ajaxResult = ipxxxapi.delGame(id, userId, salePartner);
                    } catch (Exception s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameTQYY)) {

                    try {
                        ajaxResult = itqyiapi.delGame(id, userId, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameZJY)) {

                    try {
                        ajaxResult = izjyapi.delGame(id, userId, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameKJS)) {
                    try {
//                        ajaxResult = kejinapi.delGame(id, userId, salePartner);
                        if (Objects.nonNull(accountInfo.getKjsid())){
                            ajaxResult = kejinapi.delGame(id, userId, salePartner);
                        }else {
                            ajaxResult.put(CODE_TAG, 500);
                            ajaxResult.put(MSG_TAG, "无此三放ID");
                        }
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameHHB)) {

                    try {
                        ajaxResult = ihhbapi.addAndEditAndDelGame(accountInfo, "del", userId, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameYXG)) {
                    //游戏阁接口
                    try {
                        ajaxResult = iyxgapi.delGame(accountInfo, userId, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNamePZZ)) {
                    //盼之接口
                    try {
                        ajaxResult = ipanzhiapi.delGame(id, userId, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameJYM)) {
                    //交易猫接口
                    try {
                        ajaxResult = ijymapi.delGame(accountInfo, userId, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameSDZ)) {
                    //闪电猪接口
                    try {
                        ajaxResult = isdzapi.delGame(accountInfo, userId, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameCR)) {
                    //超人
                    try {
                        ajaxResult = crapi.delGame(id, userId, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameYDD)) {
                    //虞都接口
                    try {
                        ajaxResult = ydddApi.delGame(id, userId, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameLXY)) {
                    //乐逍遥
                    try {
                        ajaxResult = lxyapi.delGame(id, userId, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameCYX)) {
                    //畅游星
                    try {
                        ajaxResult = cyxapi.delGame(id, userId, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameLJ)) {
                    //龙将
                    try {
                        ajaxResult = iljapi.delGame(accountInfo, userId, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameJYY)) {
                    //交易游
                    try {
                        //(1,添加) (2,修改)(3,上下架)
                        ajaxResult = jyyapi.addAndEditAndDelGame(accountInfo, userId, 3, true, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameKG)) {
                    //凯哥
                    try {
                        ajaxResult = ikgapi.delGame(accountInfo, userId, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameYX915)) {
                    //YX915
                    try {
                        ajaxResult = iyx915api.delGame(accountInfo, userId, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameYZJ)) {
                    //游之境
                    try {
                        ajaxResult = iyzjapi.delGame(accountInfo, userId, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.getSaleNameKM)) {
                    //酷猫
                    try {
                        ajaxResult = kmapi.delGame(accountInfo, userId, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameZHUAN)) {
                    //酷猫
                    try {
                        ajaxResult = zhuanapi.delGame(accountInfo, salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameSBO)) {
                    //少伯
                    try {
                        ajaxResult = sboapi.delGame(accountInfo.getId(), accountInfo.getCreateId(), salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameLDD)) {
                    //老达
                    try {
                        ajaxResult = ldapi.delGame(accountInfo, accountInfo.getCreateId(), salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameLDDV2)) {
                    //老达v2
                    try {
                        ajaxResult = ldv2API.delGame(accountInfo, accountInfo.getCreateId(), salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameQSHAN)) {
                    //青山
                    try {
                        ajaxResult = qshanapi.delGame(accountInfo.getId(), accountInfo.getCreateId(), salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameBQW)) {
                    //霸气玩
                    try {
                        ajaxResult = bqwapi.delGame(accountInfo, accountInfo.getCreateId(), salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameXINGL)) {
                    //戏仔
                    try {
                        ajaxResult = ipxapi.delGame(accountInfo, accountInfo.getCreateId(), salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameLSHEN)) {
                    //雷神
                    try {
                        ajaxResult = lshenapi.delGame(accountInfo, accountInfo.getCreateId(), salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameYDDV2)) {
                    //雷神
                    try {
                        ajaxResult = ydddv2Api.delGame(accountInfo.getId(), accountInfo.getCreateId(), salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameMENGQ)) {
                    //萌奇
                    try {
                        //ajaxResult = mengqapi.delGame(accountInfo, accountInfo.getCreateId(), salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameWYOU)) {
                    //无忧
                    try {
                        ajaxResult = wuyouapi.delGame(accountInfo, accountInfo.getCreateId(), salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameKGH)) {
                    //看个号
                    try {
                        ajaxResult = kangehaoapi.delGame(id, accountInfo.getCreateId(), salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameKAKA)) {
                    //卡卡
                    try {
                        ajaxResult = kakaapi.delGame(accountInfo, accountInfo.getCreateId(), salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                }else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameMHW)) {
                    //买号玩
                    try {
                        ajaxResult = mhwapi.delGame(accountInfo, accountInfo.getCreateId(), salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                }else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameSL)) {
                    //三乐
                    try {
                        ajaxResult = slapi.addAndEditAndDelGame(accountInfo, "2", salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                }else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleName7881)) {
                    // 7881
                    try {
                        ajaxResult = iyx7881API.delGame(accountInfo, accountInfo.getCreateId(), salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                }else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameTXY)) {
                    //天下游
                    try {
                        ajaxResult = txyapi.delGame(accountInfo.getId(), userId,salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                }else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameMLY)) {
                    //米来游
                    try {
                        ajaxResult = izjyapi.delGame(accountInfo.getId(), userId,salePartner);
                    } catch (GlobalException s) {
                        ajaxResult.put(CODE_TAG, 500);
                        ajaxResult.put(MSG_TAG, s.getMessage());
                    }
                }
                delInterRec(accountInfo.getId(),salePartner.getSaleName());
                if (1 == delType) {
                    insertOutRec(ajaxResult, accountInfo, LCConstant.interDel, salePartner,taskId);
                }
            }
        }

    }

    private void add(Long saleId, AjaxResult ajaxResult, AccountInfo accountInfo,Long taskId) {
        this.operType = "2";
//        price(saleId, userId, accountInfo);
        SalePartner salePartner = salePartnerMapper.selectSalePartnerById(saleId);
        if (Objects.equals(accountInfo.getAccountType(), "3")) {
            return;
        }
//        if (!Objects.equals(salePartner.getSaleName(),LCConstant.getSaleNameZHUAN) && accountInfo.getPrice().compareTo(new BigDecimal(300)) < 0){
//            ajaxResult.put(CODE_TAG, 500);
//            ajaxResult.put(MSG_TAG, "价格太低，不推送");
//            insertOutRec(ajaxResult, accountInfo, LCConstant.interEdit, salePartner,taskId);
//            return;
//        }
        if (accountInfo.getPrice().compareTo(new BigDecimal(300)) < 0){
            accountInfo.setPrice(accountInfo.getPrice().add(new BigDecimal(50)));
        }
//        if (Objects.nonNull(accountInfo.getPrice())) {
//            BigDecimal add = new BigDecimal(salePartner.getSeleep()).add(new BigDecimal(100));
//            BigDecimal divide = add.divide(new BigDecimal(100));
//            BigDecimal multiply = accountInfo.getPrice().multiply(divide);
//            accountInfo.setPrice(multiply);
//        } else {
//            accountInfo.setPrice(this.price);
//        }
        Long userId = accountInfo.getCreateId();
//                //老曹接口
        boolean b = true;
        if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameLCC)) {
            if (true) {
                try {
                    ajaxResult = lcapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameMMM)) {
            //米马接口
            if (b) {
                try {
                    ajaxResult = immapi.addAndEditGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNamePXXX)) {
            //螃蟹接口
            if (b) {
                try {
                    ajaxResult = ipxxxapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameTQYY)) {
            //淘气游接口
            if (b) {
                try {
                    ajaxResult = itqyiapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameJYM)) {
            //交易猫接口
            if (b) {
                try {
                    ajaxResult = ijymapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }

            }

        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameZJY)) {
            //指间游接口
            if (b) {
                try {
                    ajaxResult = izjyapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameKJS)) {
            //氪金兽接口
            if (b) {
                try {
                    ajaxResult = kejinapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameHHB)) {
            //换号吧接口
            if (b) {
                try {
                    ajaxResult = ihhbapi.addAndEditAndDelGame(accountInfo, "add", userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameYXG)) {
            //游戏阁接口
            if (b) {
                try {
                    ajaxResult = iyxgapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNamePZZ)) {
            //盼之接口
            if (b) {
                try {
                    ajaxResult = ipanzhiapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameSDZ)) {
            //闪电猪
            if (b) {
                try {
                    ajaxResult = isdzapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameCR)) {
            //超人

            if (b) {
                try {
                    ajaxResult = crapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameYDD)) {
            //虞都
            if (b) {
                try {
                    ajaxResult = ydddApi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameLXY)) {
            //乐逍遥
            if (b) {
                try {
                    ajaxResult = lxyapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameCYX)) {
            //畅游星
            if (b) {
                try {
                    ajaxResult = cyxapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameLJ)) {
            //龙将接口
            if (b) {
                try {
                    ajaxResult = iljapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameJYY)) {
            //交易游
            try {
                //(1,添加) (2,修改)(3,上下架)
                ajaxResult = jyyapi.addAndEditAndDelGame(accountInfo, userId, 1, false, salePartner);
            } catch (GlobalException s) {
                ajaxResult.put(CODE_TAG, 500);
                ajaxResult.put(MSG_TAG, s.getMessage());
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameKG)) {
            //凯哥接口
            if (b) {
                try {
                    ajaxResult = ikgapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameYX915)) {
            //YX915
            if (b) {
                try {
                    ajaxResult = iyx915api.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameYZJ)) {
            //游之境
            if (b) {
                try {
                    ajaxResult = iyzjapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.getSaleNameKM)) {
            //酷猫
            if (b) {
                try {
                    ajaxResult = kmapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameZHUAN)) {
            //转转
            if (b) {
                try {
                    ajaxResult = zhuanapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameSBO)) {
            //少伯
            if (b) {
                try {
                    ajaxResult = sboapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameLDD)) {
            //老达
            if (b) {
                try {
                    ajaxResult = ldapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameLDDV2)) {
            //老达v2
            if (b) {
                try {
                    ajaxResult = ldv2API.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameQSHAN)) {
            //青山
            if (b) {
                try {
                    ajaxResult = qshanapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameBQW)) {
            //霸气玩
            if (b) {
                try {
                    ajaxResult = bqwapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameXINGL)) {
            //破晓
            if (b) {
                try {
                    ajaxResult = ipxapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameLSHEN)) {
            //雷神
            if (b) {
                try {
                    ajaxResult = lshenapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameYDDV2)) {
            //雷神
            if (b) {
                try {
                    ajaxResult = ydddv2Api.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameMENGQ)) {
            //萌奇
            if (b) {
                try {
                    ajaxResult = mengqapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameWYOU)) {
            //无忧
            if (b) {
                try {
                    ajaxResult = wuyouapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameKGH)) {
            //看个号
            if (b) {
                try {
                    ajaxResult = kangehaoapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameKAKA)) {
            //卡卡
            if (b) {
                try {
                    ajaxResult = kakaapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameMHW)) {
            //买号玩
            if (b) {
                try {
                    ajaxResult = mhwapi.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        } else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameSL)) {
            //三乐
            if (b) {
                try {
                    ajaxResult = slapi.addAndEditAndDelGame(accountInfo, "1", salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        }else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleName7881)) {
            // 7881
            if (b) {
                try {
                    ajaxResult = iyx7881API.addGame(accountInfo, userId, salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        }else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameTXY)) {
            //天下游
            if (b) {
                try {
                    ajaxResult = txyapi.addGame(accountInfo, userId,salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        }else if (null != salePartner && Constants.STR_1.equals(salePartner.getStatus()) && salePartner.getSaleName().contains(LCConstant.saleNameMLY)) {
            //米来游
            if (b) {
                try {
                    ajaxResult = izjyapi.addGame(accountInfo, userId,salePartner);
                } catch (GlobalException s) {
                    ajaxResult.put(CODE_TAG, 500);
                    ajaxResult.put(MSG_TAG, s.getMessage());
                }
            }
        }

        getOutRecAndInterRec(ajaxResult, salePartner.getSaleName(), salePartner, accountInfo,taskId);
        //新增接口走定时任务
//        try {
//            Thread.sleep(2000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
    }

    private void delInterRec(Long id, String saleName) {
        InterRec interRec = new InterRec();
        interRec.setAccountId(id);
        interRec.setSaleCode(saleName);
        int i = interRecService.deleteInterRec(id, saleName);
//        List<InterRec> interRecs = interRecService.selectInterRecList(interRec);
//        for (InterRec rec : interRecs) {
//            int i = interRecService.deleteInterRecById(rec.getId());
//        }
    }

    @Transactional
    public void getOutRecAndInterRec(AjaxResult ajaxResult, String saleNameLCC, SalePartner salePartner, AccountInfo accountInfo,Long taskId) {
        insertOutRec(ajaxResult, accountInfo, LCConstant.interAdd, salePartner,taskId);
        interRecService.save(saleNameLCC, accountInfo.getId(), accountInfo.getCreateId());
//        Integer code = MapUtils.getInteger(ajaxResult, CODE_TAG);
//        Object data = MapUtils.getObject(ajaxResult, "data");
//        String s = JSONObject.toJSONString(data);
//        JSONObject jsonObject = JSONObject.parseObject(s);
//        if (Objects.equals(200, jsonObject.getInteger("code"))) {
//            interRecService.save(saleNameLCC, accountInfo.getId(), userId);
//        }
    }


    /**
     * 封装入参记录（保存推送记录）
     *
     * @param ajaxResults
     * @param interType
     * @return
     */
    @Transactional
    public void insertOutRec(AjaxResult ajaxResults, AccountInfo accountInfo,
                             String interType, SalePartner salePartner,Long taskId) {
        ApiTaskPool apiTaskPool = new ApiTaskPool();
        if (Objects.nonNull(taskId)) {
            apiTaskPool = apiTaskPoolMapper.selectApiTaskPoolById(taskId);
            if (Objects.nonNull(apiTaskPool)){
                ApiReqCopy apiReqCopy = new ApiReqCopy();
                BeanUtils.copyProperties(apiTaskPool,apiReqCopy);
                apiReqCopyMapper.insertApiReqCopy(apiReqCopy);
                apiTaskPoolMapper.deleteApiTaskPoolById(taskId);
                if (LCConstant.interDel.equals(interType)){
                    artRecMapper.deleteArtRecCode(accountInfo.getId(),salePartner.getId());
                }
            }
        }

        OutRec outRec = new OutRec();
        outRec.setAccountid(accountInfo.getId());
        outRec.setType(accountInfo.getType());
        outRec.setSupllyid(accountInfo.getCreateId());
        Long userId = accountInfo.getCreateId();
        if (Objects.isNull(userId) || 0l == userId) {
            if (Objects.nonNull(apiTaskPool)) {
                outRec.setCreateId(apiTaskPool.getCreateId());
            } else {
                outRec.setCreateId(1l);
            }
        } else {
            outRec.setCreateId(userId);
        }

        Long accountId = accountInfo.getId();
        if (!Objects.isNull(salePartner)) {
            outRec.setSaleId(salePartner.getName());
            outRec.setSalecode(salePartner.getSaleName());
            /**
             * 格式：
             * 成功条数：100
             * 失败条数：200
             * 失败原因：
             * id:errInfo
             */
            StringBuffer result = new StringBuffer();
            int success = 0;
            int error = 0;
            StringBuffer errInfo = new StringBuffer();
            Integer code = MapUtils.getInteger(ajaxResults, CODE_TAG);
            String msg = "";
            String req = "";
            String res = "";
            if (Objects.equals(HttpStatus.SUCCESS, code)) {
                Object data = MapUtils.getObject(ajaxResults, "data");
                String s = JSONObject.toJSONString(data);
                JSONObject jsonObject = JSONObject.parseObject(s);
                if(StringUtils.isNotEmpty(s) && StringUtils.isNotEmpty(jsonObject)){
                    req = jsonObject.getString("req");
                    res = jsonObject.getString("res");
                    outRec.setReq(req);
                    outRec.setRes(res);
                    if (Objects.equals(500, jsonObject.getInteger("code"))) {
                        error++;
                        msg = MapUtils.getString(jsonObject, MSG_TAG);
                        errInfo.append(msg + "\n");
                    } else {
                        success++;
                        //成功
                        if (LCConstant.interAdd.equals(interType)){
                            ArtRec artRec = new ArtRec();
                            artRec.setAccountId(accountId);
                            artRec.setCreateId(accountInfo.getCreateId());
                            artRec.setType(interType);
                            artRec.setConfig(salePartner.getId());
                            artRec.setSaleCode(salePartner.getSaleName());
                            artRecMapper.insertArtRec(artRec);
                        }
                    }
                }
            } else {
                error++;
                msg = MapUtils.getString(ajaxResults, MSG_TAG);
                errInfo.append(accountId + ":" + msg + "\n");
                outRec.setRes(msg);
            }
            result.append("成功：" + success +
                    "条,失败：" + error + "条,失败原因：" + errInfo + ",id为" + accountId);
            outRec.setResult(result.toString());
            outRec.setSuccessCount(success);
            outRec.setErrCount(error);
            outRec.setInter(interType);
            outRec.setCreateTime(DateUtils.getNowDate());
            outRecMapper.insertOutRec(outRec);
        }
    }

//    private void apiTaskPool(Long taskId) {
//        if (Objects.equals(operType, "1") && Objects.nonNull(taskId)) {
//            ApiTaskPool apiTaskPool = apiTaskPoolMapper.selectApiTaskPoolById(taskId);
//            apiTaskPool.setCountt(apiTaskPool.getCountt() + 1);
//            this.apiTaskPool = apiTaskPool;
//            apiTaskPoolMapper.updateApiTaskPool(apiTaskPool);
//        }
//    }

    public void setAccountInfoList(List<AccountInfo> accountInfoList) {
        this.accountInfoList = accountInfoList;
    }


}
